<template>
  <div class="main_box">
    <a-card>
      <a-table class="main_table"
               :columns="columns"
               :data="itemList"
               size="large"
               style="min-height: 656px;"
               @row-click="doTeam">
        <template #submitslot="{record}">
          {{record}}
        </template>
      </a-table>
    </a-card>
  </div>
</template>

<script setup lang="ts">
import { computed, onMounted, reactive, ref } from "vue";
import store from "@/store";
import AccessEnum from "@/access/accessEnum";
import { QuestionControllerService, QuestionSubmitControllerService, UserControllerService } from "../../generated";
import { Message } from "@arco-design/web-vue";
import router from "@/router";
import * as echarts from 'echarts';
import { useRoute } from "vue-router";

const itemList = reactive([]);
const route = useRoute();
const contestid = ref();
const tids = ref();

onMounted(async () => {
  tids.value = route.query?.tids;
  contestid.value = route.query?.contestid;
  if (!tids.value) return;
  // 通过tids 拿题目
  let res = await QuestionControllerService.getQuestionListByTidsUsingPost({ tids:tids.value });
  let {code, msg} = res;
  console.log('res', res);
  if(code === 0) {
    itemList.length=0;
    itemList.push(...res.data);
  }else {
    Message.error(msg);
  }
})

const columns = [
  {
    title: '题号',
    dataIndex: 'id'
  }, {
    title: '标题',
    dataIndex: 'title',
  }
];

const doTeam = (team:any ) => {
  if (!contestid.value) {
    Message.error("跳转失败");
    return;
  }
  const userRole = store.state.user.curUser.userRole;
  // 判断权限 如果是user
  if (userRole == AccessEnum.USER) {
    // 跳转做题页面（传递题目数据）
    router.push({ path: '/submit_online_contest_team', query: { id: team.id, contestid:contestid.value} });
  }else if (userRole == AccessEnum.NOT_LOGIN) {
    // 跳转到登录页面
    router.push({ path: '/user/login'});
  }
}
</script>

<style scoped>
.main_box{
  height: 100%;
  width: 100%;
}
.search_box {
  margin-top: 20px;
  margin-bottom: 20px;
}
.main_table {
  width: 100%;
}
.arco-space {
  display: block;
}
tr {
  height: 60px;
}
.search_title_font {
  font-weight: bold;
  text-align: center;
  color: #4c5a69;
  line-height: 35px;
}
#calend_box {
  width: 1200px;
  height: 250px;
  margin: 0 auto;
}
</style>